<template>
    <div>
        <iview-table
                ref="iviewTable"
                :span1=16
                :span2=8
                :status="status"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :defaultFilters="queryModel.defaultFilters"
                v-on="{changeTotalSize:changeTotalSize}">
        </iview-table>
        <br>
        <iview-page
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
        </iview-page>
    </div>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    import iviewPage from '@/view/common/page/Page.vue';
    export default {
        components: {
            iviewTable,
            iviewPage
        },
        props: {
            // 列表选中状态
            status: {
                type: Boolean,
                default: false
            },
            projectTypeId: {
                type: Number,
                default: -1
            },
            parentId: {
                type: Number,
                default: -1
            }
        },
        data () {
            return {
                selectRows: [],
                queryModel: {
                    // 网关代理路径(必须)+资源路径(可选)
                    baseURL: '/user/project',
                    defaultFilters: [
                        {'field': 'level', 'value1': 1, 'operate': '=='}
                    ]
                },
                dataModel: {
                    menuId: 0,
                    columns: [
                        {
                            title: '项目类别',
                            key: 'projectTypeName',
                            width: 150
                        },
                        {
                            title: '项目名称',
                            key: 'name'
                        },
                        {
                            title: '项目价格',
                            key: 'price',
                            width: 150
                        },
                        {
                            title: '操作',
                            width: 150,
                            align: 'center',
                            render: (h, params) => {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'default'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.select(params.row)
                                            }
                                        }
                                    }, '选择')
                                ]);
                            }
                        }
                    ],
                    order: 'id desc'
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 10,
                    pageSizeOpts: [5, 10, 20, 50]
                }
            };
        },
        methods: {
            select (row) {
                this.$emit('select', row)
            },
            refresh () {
                this.$refs.iviewTable.refresh()
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
            },
            changePageSize (pageSize) {
                this.pageModel.pageSize = pageSize
            },
            init () {
                this.refresh()
            }
        },
        mounted () {
            this.init()
        },
        watch: {
            projectTypeId: function (val, oldVal) {
                if (val !== -1) {
                    this.queryModel.defaultFilters[0] = {'field': 'project_type_id', 'value1': val, 'operate': '=='}
                    this.queryModel.defaultFilters[1] = {'field': 'parent_id', 'operate': 'IS NULL'}
                    this.refresh()
                }
            },
            parentId: function (val, oldVal) {
                if (val !== -1) {
                    this.queryModel.defaultFilters[0] = {'field': 'parent_id', 'value1': val, 'operate': '=='}
                    this.refresh()
                }
            }
        }
    }
</script>

<style>

</style>
